<div class="mini-toolbar" style="padding:0px;margin:0px;border-bottom:0;width:100%;">
	<table style="width:100%;">
		<tr>
			<td style="width:100%;">
				<a class="mini-button" iconCls="icon-addnew" id="areaAdd" plain="true">增加直属行政区域</a>
				<a class="mini-button" iconCls="icon-edit" id="areaEdit" plain="true">修改</a>
				<a class="mini-button" iconCls="icon-remove" id="areaDel" plain="true">删除</a>
			</td>
		</tr>
	</table>
</div>
<div id="treegrid1" class="mini-treegrid" style="width:100%;height:98%;" url="/common/area" showTreeIcon="false" treeColumn="name" idField="id" parentField="parent" resultAsTree="false" allowSelect="true">
    <div property="columns">
        <div width="12px" type="indexcolumn"></div>
        <div name="name" field="name" width="250px">行政区域名称</div>
        <div field="updated" width="80px" headerAlign="center" align="center" dateFormat="yyyy-MM-dd">更新时间</div>
    </div>
</div>
<script type="text/javascript">
// 画面初期化
mini.parse();
var urlDel = "/basic/areaDel";
var urlUpd = "/basic/areaUpd?agency=0";
var treegrid = mini.get("treegrid1");
var rowid = 0;
treegrid.expandAll();

$("#areaAdd").click(function(){
	var row = treegrid.getSelectedNode();
	if (row != null) {
		mini.open({
            url: "/basic/areaEdit",
            title: "新增行政区域", width: 300, height: 150,
            onload: function()
            {
                var iframe = this.getIFrameEl();
                var data = {action: "new",id:row.id};
                iframe.contentWindow.SetData(data);
            },
            ondestroy:function(action)
            {
            	treegrid.load("/common/area");
            	treegrid.expandAll();
            }
        });
		$(".mini-panel-border .mini-panel-body iframe").css("height","95%");
	} else {
		parent.$.dooDialog.alert("请选中一条记录");
	}
});

$("#areaEdit").click(function(){
	var row = treegrid.getSelectedNode();
	if (row != null) {
		mini.open({
            url: "/basic/areaEdit",
            title: "修改行政区域", width: 300, height: 150,
            onload: function()
            {
                var iframe = this.getIFrameEl();        		
                var data={action:"edit",id:row.id,name:row.name};
                iframe.contentWindow.SetData(data);
            },
            ondestroy:function(action)
            {
            	treegrid.load("/common/area");
            	treegrid.expandAll();
            }
        });
		$(".mini-panel-border .mini-panel-body iframe").css("height","95%");
	} else {
		parent.$.dooDialog.alert("请选中一条记录");
	}
});

$("#areaDel").click(function(){
	var row = treegrid.getSelectedNode();
	if (row != null) {
		if(row.id != 1){
			parent.$.dooDialog.confirm("你确定要删除这行政区域吗？",function(){
				$.post('/basic/areaDel',{id:row.id},function(data){
					if(data.code=='OK'){
						treegrid.removeNode(row);
						return false;
					}else{
						parent.$.dooDialog.alert('这个行政区域删除失败！');
						return false;
					}
				},'json');
			});
		}else{
			parent.$.dooDialog.alert("不能删除国家！");
		}
	} else {
		parent.$.dooDialog.alert("请选中一条记录");
	}
});
</script>
